' Versa Gauge Dual main test program
' use with R61505V Driver and Fonts.txt file stored in the Library Flash area...

' franklingothic_normal.bas Assigned to Font #2
' Font type    : Full (95 characters)
' Font size    : 16x16 pixels
' Memory usage : 3044 bytes
' The character just before the lowercase 'a' normal is a grave accent, but
' here changed to the Degree character to have the possibility to show on the TFT screen.

' SevenSegNumFont.bas Assigned to Font #3
' Font type    : Numeric (10 characters)
' Font size    : 32x50 pixels
' Memory usage : 2004 bytes

' various_symbols.bas Assigned to Font #4
' Font type    : Full (95 characters)
' Font size    : 16x16 pixels
' Memory usage : 3044 bytes

Option default none
Option explicit
CPU 48
Const displaystring="CHT`F" ' the ` char is the degree symbol
Dim integer Needle_1_lastx1, Needle_1_lastx2, Needle_1_lasty1, Needle_1_lasty2, needle_1_lastangle ' GAUGE 1 variables
Dim integer Needle_2_lastx1, Needle_2_lastx2, Needle_2_lasty1, Needle_2_lasty2, needle_2_lastangle ' GAUGE 2 variables

Dim integer G1_val, G2_val, N1_val, N2_val, N2_pos=460, radius, firsttime=1, needlelength, drawcolor
radius=106 ' center 110-4
needlelength= radius\5*4-1
'Print needlelength ' 83
SetPin 11,dout ' LED Backlight Pin
Pin(11)=1 ' 1 = ON (could use PWM to vary brightness)

CLS
Circle 110,110,109,2,1,RGB(white)' create outer bezel
Circle 110,110,radius-24,2,1,RGB(white)' create inner bezel
Line 108,193,108,220,4,RGB(white)' bottom seperator
Line 110,1,110,27,2,RGB(white)' top seperator

Line 30,114,71,114,4,RGB(white)' left bottom bar
Line 148,102,190,102,4,RGB(white)' right top bar

Text 110,110,displaystring,cm,2,1,RGB(black),RGB(white) ' string centred in black center bar area
Text 50,100,"1",cm,2,1,RGB(white) ' CHT 1
Text 170,120,"2",cm,2,1,RGB(white) ' CHT 2

Text 50,80,"Q",cm,4,1,RGB(white) ' Font 4 - is Left arrow char
'Text 50,140,"A",cm,4,1,RGB(green) ' Font 4 - is X checkbox char
Text 170,140,"R",cm,4,1,RGB(white) ' Font 4 - is right arrow char
'Text 170,80,"A",cm,4,1,RGB(green) ' Font 4 - is X checkbox char

'End

Do ' input value then, seek to match
  Input "Gauge 1 value"; G1_val
  If N1_val<G1_val Then inc_Needle_1
  If N1_val>G1_val Then dec_Needle_1
  Input "Gauge 2 value"; G2_val
  If N2_val<G2_val Then inc_Needle_2
  If N2_val>G2_val Then dec_Needle_2
Loop
End

Sub inc_Needle_1
  Do
    N1_val=N1_val+1
    set_color(N1_val)
    Text 110,70,Str$(N1_val,3,0,"0"),cm,3,1,drawcolor
    If N1_val>101 And N1_val<458 Then needle_1(110,110,needlelength,N1_val\2-49-180,drawcolor)
    If N1_val>998 Then Exit Do
  Loop Until N1_val=G1_val
End Sub

Sub dec_Needle_1
  Do
    N1_val=N1_val-1
    set_color(N1_val)
    Text 110,70,Str$(N1_val,3,0,"0"),cm,3,1,drawcolor
    If N1_val>101 And N1_val<458 Then needle_1(110,110,needlelength,N1_val\2-49-180,RGB(black))
    If N1_val<0 Then Exit Do
  Loop Until N1_val=G1_val
End Sub

Sub inc_Needle_2
  Do
    N2_val=N2_val+1
    N2_pos=N2_pos-1
    set_color(N2_val)
    Text 110,150,Str$(N2_val,3,0,"0"),cm,3,1,drawcolor
    If N2_val>101 And N2_val<458 Then needle_2(110,110,needlelength,N2_pos\2,drawcolor)
    If N2_val>998 Then Exit Do
  Loop Until N2_val=G2_val
End Sub

Sub dec_Needle_2
  Do
    N2_val=N2_val-1
    N2_pos=N2_pos+1
    set_color(N2_val)
    Text 110,150,Str$(N2_val,3,0,"0"),cm,3,1,drawcolor
    If N2_val>101 And N2_val<458 Then needle_2(110,110,needlelength,N2_pos\2,RGB(black))
    If N2_val<0 Then Exit Do
  Loop Until N2_val=G2_val
End Sub

Sub set_color(color_val As integer)
      If color_val<100 Then drawcolor=RGB(white)
      If color_val>100 And color_val<300 Then drawcolor=RGB(green)
      If color_val>300 And color_val<400 Then drawcolor=RGB(yellow)
      If color_val>400 And color_val<999 Then drawcolor=RGB(red)
End Sub

' Routine to draw a pointer
' Parameters are:
' x-coordinate of centre of gauge
' y-coordinate of centre of gauge
' pointer length
' radial of pointer to be drawn (0-360 degrees)
' colour to draw pointer
'
Sub needle_1(x As integer, y As integer, size As integer, angle As integer, col As integer)
Local integer x1,y1,x2,y2,size2
    size2=size+24
    x1=Sin(Rad(angle))*size + x
    y1=-Cos(Rad(angle))*size + y
    x2=Sin(Rad(angle))*size2 + x
    y2=-Cos(Rad(angle))*size2 + y
    If angle<needle_1_lastangle Then ' Erase old line
      Line Needle_1_lastx1,Needle_1_lasty1,Needle_1_lastx2,Needle_1_lasty2,,0
    EndIf
      Line x1,y1,x2,y2,,col
    needle_1_lastangle=angle
    Needle_1_lastx1=x1
    Needle_1_lastx2=x2
    Needle_1_lasty1=y1
    Needle_1_lasty2=y2
End Sub

Sub needle_2(x As integer, y As integer, size As integer, angle As integer, col As integer)
Local integer x1,y1,x2,y2,size2
    size2=size+24
    x1=Sin(Rad(angle))*size + x
    y1=-Cos(Rad(angle))*size + y
    x2=Sin(Rad(angle))*size2 + x
    y2=-Cos(Rad(angle))*size2 + y
    If angle>needle_2_lastangle Then ' Erase old line
      Line Needle_2_lastx1,Needle_2_lasty1,Needle_2_lastx2,Needle_2_lasty2,,0
    EndIf
      Line x1,y1,x2,y2,,col
    needle_2_lastangle=angle
    Needle_2_lastx1=x1
    Needle_2_lastx2=x2
    Needle_2_lasty1=y1
    Needle_2_lasty2=y2
End Sub                                                  